/*
 * RandomGenerator.java &xiaocao000 2009-1-9
 */
package com.xiaocao000.common.utils;

/**
 * @author &xiaocao000
 */
public class RandomGenerator
{
	private static final int BUFSIZE = 100;
	private static double[] buf = new double[BUFSIZE];
	static
	{
		for (int i = 0; i < buf.length; i++)
		{
			buf[i] = java.lang.Math.random();
		}
	}

	private static double nextRandom()
	{
		int pos = (int) (java.lang.Math.random() * BUFSIZE);
		if (pos == BUFSIZE)
		{
			pos = BUFSIZE - 1;
		}
		double r = buf[pos];
		buf[pos] = java.lang.Math.random();
		return r;
	}

	public static int getRandomInt(int low, int high)
	{
		return low + (int)((high - low + 1) * nextRandom());
	}
	
	public static float getRandomFloat(float low, float high)
	{
		return low + (float)((high - low + 1) * nextRandom());
	}
	
	public static double getRandomDouble(double low, double high)
	{
		return low + (double)((high - low + 1) * nextRandom());
	}
	
	public static long getRandomLong(long low, long high)
	{
		return low + (long)((high - low + 1) * nextRandom());
	}
	
	public static String getRandomDateString()
	{
		java.text.DateFormat df = new java.text.SimpleDateFormat();
		java.util.Date date = new java.util.Date();
		return df.format(date);
	}
}
